package com.zelin.web.servlet;

import com.zelin.pojo.Student;
import com.zelin.service.StudentService;
import com.zelin.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/11/1-11:00
 * ------------------------------
 */
@WebServlet("/student")
public class StudentServlet extends HttpServlet {
    private StudentService studentService;
    @Override
    public void init() throws ServletException {
        studentService = new StudentServiceImpl();
    }

    //1. 重写service（）可以处理任何请求
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.1 查询所出所有学生列表
        List<Student> students = studentService.findAll();

        //1.2 将所有学生列表放到请求作用域（一次请求数据就可以取出）
        req.setAttribute("students",students);

        //1.3 进行页面的跳转（一次请求）
        req.getRequestDispatcher("/WEB-INF/student/list.jsp").forward(req,resp);
    }
}
